#   Copyright 2007 - 2008 MySQL AB, 2008 - 2009 Sun Microsystems, Inc.  All rights reserved.
#
#   The MySQL Connector/C++ is licensed under the terms of the GPL
#   <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
#   MySQL Connectors. There are special exceptions to the terms and
#   conditions of the GPL as it is applied to this software, see the
#   FLOSS License Exception
#   <http://www.mysql.com/about/legal/licensing/foss-exception.html>.

SET(CMAKE_VERBOSE_MAKEFILE 0)

SET(MYSQLCPPCONN_BUILD_EXAMPLES 1 CACHE BOOL "build-examples")
IF(MYSQLCPPCONN_BUILD_EXAMPLES)
	INCLUDE_DIRECTORIES(${MYSQLCPPCONN_SOURCE_DIR})
	LINK_DIRECTORIES(${MYSQLCPPCONN_SOURCE_DIR}/cppconn)

	IF(WIN32)
		INCLUDE_DIRECTORIES(${MYSQLCPPCONN_SOURCE_DIR/cppconn})

		IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
			LINK_DIRECTORIES(${MYSQL_DIR}/lib/debug)
		ELSEIF(CMAKE_BUILD_TYPE STREQUAL "")
			LINK_DIRECTORIES(${MYSQL_DIR}/lib/opt)
		ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")

		ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS")

		SET(MY_TARGET_LINK_LIBRARIES mysqlcppconn libmysql)
	ELSEIF(NOT WIN32)
		SET(MY_TARGET_LINK_LIBRARIES mysqlcppconn-static mysqlclient_r)
	ENDIF(WIN32)

	IF(CMAKE_COMPILER_IS_GNUCC AND MYSQLCPPCONN_GCOV_ENABLE)
		SET(MY_GCOV_LINK_LIBRARIES gcov)
	ENDIF(CMAKE_COMPILER_IS_GNUCC AND MYSQLCPPCONN_GCOV_ENABLE)

	ADD_EXECUTABLE(connect connect.cpp)
	SET_TARGET_PROPERTIES(connect PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(connect ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

	ADD_EXECUTABLE(connection_meta_schemaobj connection_meta_schemaobj.cpp)
	SET_TARGET_PROPERTIES(connection_meta_schemaobj PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(connection_meta_schemaobj ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

	ADD_EXECUTABLE(debug debug.cpp)
	SET_TARGET_PROPERTIES(debug PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(debug ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

	ADD_EXECUTABLE(exceptions exceptions.cpp)
	SET_TARGET_PROPERTIES(exceptions PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(exceptions ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

	ADD_EXECUTABLE(prepared_statement prepared_statement.cpp)
	SET_TARGET_PROPERTIES(prepared_statement PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(prepared_statement ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

	ADD_EXECUTABLE(resultset resultset.cpp)
	SET_TARGET_PROPERTIES(resultset PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(resultset ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

	ADD_EXECUTABLE(resultset_binary resultset_binary.cpp)
	SET_TARGET_PROPERTIES(resultset_binary PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(resultset_binary ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})


	ADD_EXECUTABLE(resultset_meta resultset_meta.cpp)
	SET_TARGET_PROPERTIES(resultset_meta PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(resultset_meta ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

	ADD_EXECUTABLE(resultset_types resultset_types.cpp)
	SET_TARGET_PROPERTIES(resultset_types PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(resultset_types ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

	ADD_EXECUTABLE(statement statement.cpp)
	SET_TARGET_PROPERTIES(statement PROPERTIES
						LINK_FLAGS "${MYSQL_LINK_FLAGS} $ENV{LDFLAGS}"
						COMPILE_FLAGS "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")
	TARGET_LINK_LIBRARIES(statement ${MY_TARGET_LINK_LIBRARIES} ${MY_GCOV_LINK_LIBRARIES} ${MYSQLCPPCONN_STLPORT_LIB})

ENDIF(MYSQLCPPCONN_BUILD_EXAMPLES)

MESSAGE(STATUS "Configuring examples")
